#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

bool luck[4748];
int number[4748];

class TheLuckyGameDivTwo {
public:
	int find(int, int, int, int);
	bool lucky(int n) {
		stringstream s;
		s << n;
		string ss = s.str();
		for (int i = 0; i < ss.size(); i++) {
			if (ss[i] != '4' && ss[i] != '7')
				return false;
		}
		return true;
	}
};

int TheLuckyGameDivTwo::find(int a, int b, int jLen, int bLen) {
	memset(luck, false, sizeof(luck));
	memset(number, 0, sizeof(number));
	for (int i = a; i <= b; i++) {
		if (lucky(i)) {
			luck[i] = true;
		}
	}
	
	for(int i=a; i+bLen-1<=b; i++){
		int temp = 0;
		for(int j=0; j<bLen; j++){
			if(luck[i+j]) temp++;
		}
		number[i] = temp;
	}

	int mmax = 0;
	for (int i = a; i + jLen - 1 <= b; i++) {
		int mmin = 2000000000;
		for (int start = i; start + bLen <= i + jLen; start++) {
			if (number[start] < mmin)
				mmin = number[start];
		}
		if (mmin > mmax)
			mmax = mmin;
	}
	return mmax;
}


double test0() {
	int p0 = 1;
	int p1 = 10;
	int p2 = 2;
	int p3 = 1;
	TheLuckyGameDivTwo * obj = new TheLuckyGameDivTwo();
	clock_t start = clock();
	int my_answer = obj->find(p0, p1, p2, p3);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p4 = 0;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p4 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p4 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test1() {
	int p0 = 1;
	int p1 = 100;
	int p2 = 100;
	int p3 = 100;
	TheLuckyGameDivTwo * obj = new TheLuckyGameDivTwo();
	clock_t start = clock();
	int my_answer = obj->find(p0, p1, p2, p3);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p4 = 6;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p4 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p4 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test2() {
	int p0 = 4;
	int p1 = 8;
	int p2 = 3;
	int p3 = 2;
	TheLuckyGameDivTwo * obj = new TheLuckyGameDivTwo();
	clock_t start = clock();
	int my_answer = obj->find(p0, p1, p2, p3);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p4 = 1;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p4 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p4 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}
double test3() {
	int p0 = 1;
	int p1 = 100;
	int p2 = 75;
	int p3 = 50;
	TheLuckyGameDivTwo * obj = new TheLuckyGameDivTwo();
	clock_t start = clock();
	int my_answer = obj->find(p0, p1, p2, p3);
	clock_t end = clock();
	delete obj;
	cout <<"Time: " <<(double)(end-start)/CLOCKS_PER_SEC <<" seconds" <<endl;
	int p4 = 2;
	cout <<"Desired answer: " <<endl;
	cout <<"\t" << p4 <<endl;
	cout <<"Your answer: " <<endl;
	cout <<"\t" << my_answer <<endl;
	if (p4 != my_answer) {
		cout <<"DOESN'T MATCH!!!!" <<endl <<endl;
		return -1;
	}
	else {
		cout <<"Match :-)" <<endl <<endl;
		return (double)(end-start)/CLOCKS_PER_SEC;
	}
}

int main() {
	int time;
	bool errors = false;
	
	time = test0();
	if (time < 0)
		errors = true;
	
	time = test1();
	if (time < 0)
		errors = true;
	
	time = test2();
	if (time < 0)
		errors = true;
	
	time = test3();
	if (time < 0)
		errors = true;
	
	if (!errors)
		cout <<"You're a stud (at least on the example cases)!" <<endl;
	else
		cout <<"Some of the test cases had errors." <<endl;
}

//Powered by [KawigiEdit] 2.0!
